package com.zuoshenge.main.init;

import com.zuoshenge.init.AbstractCache;
import com.zuoshenge.main.entity.Academy;
import com.zuoshenge.main.service.AcademyService;
import com.zuoshenge.main.service.CourseService;
import com.zuoshenge.util.CaffeineCacheUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class InitAcademyCache extends AbstractCache {

    @Resource
    private CaffeineCacheUtil caffeineCacheUtil;
    @Resource
    private AcademyService academyService;
    @Value("${init.cache.academy-cache-key}")
    private String ACADEMY_CACHE_KEY;

    @Override
    public void initCache() {
        List<Academy> academyList = academyService.queryAll();
        academyList.forEach(academy -> {
            caffeineCacheUtil.set(ACADEMY_CACHE_KEY+academy.getAcademyId().toString(), academy.getAcademyName());
        });
    }

    @Override
    public <T> T getCache() {
        return null;
    }

    @Override
    public void clearCache() {

    }
}
